<?php

namespace App\Services;

use App\Exceptions\BusinessException;
use App\Helpers\ApiResponse;
use App\Helpers\ResponseEnum;

class BaseService
{
    // 引入 API 统一返回消息
    use ApiResponse;

    protected static $instance;

    public static function getInstance()
    {
        if (static::$instance instanceof static) {
            return self::$instance;
        }
        static::$instance = new static();
        return self::$instance;
    }

    protected function __construct()
    {
    }

    protected function __clone()
    {
    }

    /**
     * 业务异常返回
     * @param string $customInfo
     * @param array $codeResponse
     * @return void
     * @throws BusinessException
     */
    public function throwBusinessException(string $customInfo = '', array $codeResponse = ResponseEnum::HTTP_ERROR): void
    {
        throw new BusinessException($codeResponse, $customInfo);
    }
}
